<!--
* @Author: zhangjing
* @Date: 2025-04-07 16:51:29
* @Description: 医护管理=>
-->
<template>
	<pro-table
		ref="protable"
		rowKey="doctorId"
		:loadDataUrl="api.getList"
		:columns="columns"
		:isAdd="$_has('hosp:docterNurses:insert')"
		:isDelete="$_has('hosp:docterNurses:delete')"
		:orgId="globalOrgId"
		:isRowSelection="false"
		:extendParam="{
			orgId: globalOrgId,
		}"
		:isImport="$_has('hosp:docterNurses:import')"
		:isDefinedFilter="false"
		@selectedRowChange="onSelectChange"
		@addRecord="addRecord"
		@showDeleteConfirm="showDeleteConfirm"
		@changeSelect="changeSelect"
		@handlerReset="handlerReset"
		@importRecord="importRecord"
	>
		<div
			slot="photoPath"
			slot-scope="{ text, record }"
			style="width: 60px; height: 60px; overflow: hidden; border-radius: 100%; margin: 0 auto"
		>
			<img v-if="text" :src="fileUrl + text.split(';')[0]" style="width: 80px" />
		</div>
		<a-tag :color="text == 1 ? '#00a095' : '#d43030'" slot="status" slot-scope="{ text, record }">{{
			record.statusName
		}}</a-tag>
		<span slot="operation" slot-scope="{ text, record }" class="operation">
			<a href="javascript:;" v-has="'sys:deviceType:update'" title="编辑" class="edit" @click="editRecord(record)"
				>编辑</a
			>
			<a
				href="javascript:;"
				v-has="'sys:deviceType:update'"
				title="团队成员"
				class="edit"
				@click="details(record)"
				>团队成员</a
			>
			<a
				href="javascript:;"
				v-has="'sys:deviceType:delete'"
				title="删除"
				class="del"
				@click="showDeleteConfirm(1, record.doctorId, record.realName)"
				>删除</a
			>
		</span>
		<!-- 添加，编辑 -->
		<add-or-edit-doctor-modal
			ref="addOrEditModal"
			:api="api"
			modalTitle="团队"
			@ok="handlerRefresh"
		></add-or-edit-doctor-modal>
		<doctorModal ref="accountModal"></doctorModal>
		<importAccountModal ref="importAccountModal" @ok="handlerRefresh"></importAccountModal>
	</pro-table>
</template>

<script>
import { filterOption, filterName } from '@/utils/base.js';
import { rowSelection, recordOperation } from '@/mixins';
import { doctorManageapi, sysManageapi } from '@/api/index.js';
import addOrEditDoctorModal from './module/addOrEditDoctorModal';
import doctorModal from './module/doctorModal.vue';
import importAccountModal from './module/importAccountModal.vue';
import { mapState, mapMutations, mapActions } from 'vuex';
const columns = [
	{
		title: '所属医院',
		dataIndex: 'deptName', // data数据源中对应的字段
		key: 'deptName', // 列的关键字 如果有 dataIndex 则不需要key
		ellipsis: true,
		searchInfo: {
			type: 'treeSelect',
			value: 'deptId',
			text: '所属医院',
			defaultValue: undefined,
			optionlist: [],
			isLinkage: true, //是否联动筛选
		},
	},

	{
		title: '团队名称',
		dataIndex: 'teamName',
		key: 'teamName',
		searchInfo: {
			type: 'string',
			defaultValue: '',
		},
	},

	{
		title: '联系人',
		dataIndex: 'realName',
		key: 'realName',
		searchInfo: {
			type: 'string',
			defaultValue: '',
		},
	},
	{
		title: '联系电话',
		dataIndex: 'phone',
		key: 'phone',
		searchInfo: {
			type: 'string',
			defaultValue: '',
		},
	},

	{
		title: '团队数量',
		dataIndex: 'status',
		key: 'status',
	},
	{
		title: '操作',
		key: 'operation',
		scopedSlots: {
			customRender: 'operation',
		},
		width: 200,
		fixed: 'right',
	},
];
export default {
	name: 'studentlist',
	mixins: [rowSelection, recordOperation],
	components: {
		addOrEditDoctorModal,
		doctorModal,
		importAccountModal,
	},
	data() {
		return {
			columns,
			api: doctorManageapi.doctorUrl,
			form: this.$form.createForm(this),
			replaceFields: { children: 'children', title: 'deptName', key: 'deptId', value: 'deptId' },
			fileUrl: process.env.VUE_APP_FILE_API,
		};
	},
	computed: {},
	watch: {
		globalOrgId: {
			handler(newval, oldval) {
				this.$nextTick(() => {
					this.handlerRefresh();
				});
			},
			immediate: true, //刷新加载 立马触发一次handler
			deep: true,
		},
	},
	created() {
		this.columns = columns.filter((item) => {
			if (!(!this.isAdmin && item.key == 'deptName')) {
				return item;
			}
		});
	},
	methods: {
		setTableData(list) {
			this.tablelist = [...list];
		},

		changeSelect(e, value, item) {},

		//切换校区
		changeDept(value) {
			console.log(JSON.stringify(value));
			this.filter.deptId = value;
		},

		/* 筛选拦截，如果不需要特殊处理筛选条件，可以不做设置 */
		handlerSearch(obj) {
			this.$refs.protable && this.$refs.protable.loadTable(this.filter);
		},
		/* 刷新列表当前页 */
		handlerRefresh() {
			this.$refs.protable && this.$refs.protable.handlerRefresh();
		},
		/* 筛选条件重置, 将默认设置为undefined/[] */
		handlerReset(obj) {
			console.log('obj' + JSON.stringify(obj));
			let newcolumns = [...this.columns];
			for (var key in obj) {
				console.log(typeof obj[key]);
				if (['string', 'number'].includes(typeof obj[key])) {
					newcolumns = this.setColumnsSearchInfo(newcolumns, key, undefined, 'defaultValue');
				} else {
					if (Array.isArray(obj[key])) {
						newcolumns = this.setColumnsSearchInfo(newcolumns, key, [], 'defaultValue');
					}
				}
			}
			this.columns = [...newcolumns];
			this.orgId = '';
			this.$nextTick(() => {
				this.$refs.protable.loadTable({});
			});
		},
		details(info) {
			this.$refs.accountModal.show(info.doctorId);
		},
		importRecord() {
			this.$refs.importAccountModal.show();
		},
	},
};
</script>

<style scoped="scoped" lang="less">
.avatar {
	width: 60px;
	height: 60px;
	border-radius: 8px;
	display: block;
	margin: 0 auto;
}
.topbar {
	background: #fff;
	z-index: 6;
	-webkit-box-shadow: 0px 4px 8px rgba(19, 29, 53, 0.05);
	box-shadow: 0px 4px 8px rgba(19, 29, 53, 0.05);
	border-radius: 8px;
	margin: 0;
	margin-bottom: 10px;
	-webkit-transition: all 0.3s;
	transition: all 0.3s;
	.toolbar .refresh {
		width: 40px;
		font-size: 14px;
		margin-right: 10px;
	}
	.toolbar .ant-btn {
		width: 95px;
		font-size: 14px;
		& + .ant-btn {
			margin-left: 10px;
		}
	}

	.toolbar .ant-btn-blue .iconfont,
	.toolbar .ant-btn-green .iconfont,
	.toolbar .ant-btn-yellow .iconfont,
	.toolbar .ant-btn-primary .iconfont {
		font-size: 12px;
		margin-right: 5px !important;
	}
}
</style>
